# 作者：陈睿-cruise
# 2025年02月12日10时06分39秒
# 2979386061@qq.com
class LoggingDecorator:
    def __init__(self, func):
        self.func = func  # 保存原函数
        print(f"LoggingDecorator initialized for {func.__name__}")

    def __call__(self, *args, **kwargs):
        # 装饰器功能：在调用原函数之前添加日志
        print(f"Logging: Calling {self.func.__name__} with arguments {args} and keyword arguments {kwargs}")
        result = self.func(*args, **kwargs)  # 调用原函数
        print(f"Logging: {self.func.__name__} returned {result}")
        return result  # 返回原函数的返回值


# 使用类装饰器
@LoggingDecorator
def add(a, b):
    return a + b


# 调用被装饰的函数
add(2, 3)
